package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.exception.ExamineException;
import com.itany.pojo.Book;
import com.itany.pojo.Examine;
import com.itany.pojo.ManagerUser;
import com.itany.service.ExamineService;
import com.itany.vo.ActionResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * Author:梁辰
 * 时间:19-4-4 下午2:30
 * description:
 * version:1.0
 */
@RestController
@RequestMapping("/examine")
public class ExamineController {
    @Resource
    private ExamineService examineService;

    @RequestMapping("/findExamineByFuzzy")
    public Map<String, Object> findExamine(Integer supplierid, Book book, HttpSession session, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer rows) {

        if (null == supplierid) {
            ManagerUser sessionUser = (ManagerUser) session.getAttribute("sessionUser");
            supplierid = sessionUser.getSupplierid();
        }

        PageInfo<Examine> examine = examineService.findExamineByFuzzy(book,supplierid,page,rows);
        Map<String,Object>map=new HashMap<>();
        map.put("total",examine.getTotal());
        map.put("rows",examine.getList());
        return map;
    }
    @RequestMapping("/executeExamine")
    public ActionResult executeExamine(Examine examine) throws ExamineException {
        ActionResult ar = new ActionResult();
        examineService.executeExamine(examine);
        ar.setStatus(true);
        ar.setMsg("审核结束");
        return ar;
    }


}
